package org.lease.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.lease.common.result.Result;
import org.lease.model.entity.SystemPost;
import org.lease.model.enums.BaseStatus;
import org.lease.service.SystemPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "岗位管理")
@RestController
@RequestMapping("/admin/system/post")
public class SystemPostController {
    @Autowired
    private SystemPostService systemPostService;

    @Operation(summary = "分页查询岗位信息")
    @GetMapping("/page")
    public Result<IPage<SystemPost>> page(int current, int size) {
        Page<SystemPost> page = systemPostService.page(new Page<>(current, size));
        return Result.success(page);
    }

    @Operation(summary = "保存或更新岗位信息")
    @PostMapping("/saveOrUpdate")
    public Result save(@RequestBody SystemPost systemPost) {
        systemPostService.saveOrUpdate(systemPost);
        return Result.success();
    }

    @Operation(summary = "根据 ID 查询岗位信息")
    @GetMapping("/getById")
    public Result<SystemPost> getById(Long id) {
        SystemPost systemPost = systemPostService.getById(id);
        return Result.success(systemPost);
    }

    @Operation(summary = "根据 ID 删除岗位信息")
    @DeleteMapping("/deleteById")
    public Result removeById(Long id) {
        systemPostService.removeById(id);
        return Result.success();
    }

    @Operation(summary = "更新岗位状态")
    @PostMapping("/updateStatusByPostId")
    public Result updateStatus(Long id, BaseStatus status) {
        systemPostService.updateStatus(id, status);
        return Result.success();
    }

    @Operation(summary = "查询所有岗位")
    @GetMapping("/list")
    public Result<List<SystemPost>> list() {
        List<SystemPost> list = systemPostService.list();
        return Result.success(list);
    }
}
